﻿using GammaJul.ReSharper.GammaXaml.Highlightings.CSharp;
using JetBrains.ReSharper.Feature.Services.Bulbs;
using JetBrains.ReSharper.Intentions.QuickFixes;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Tree;

namespace GammaJul.ReSharper.GammaXaml.QuickFixes.CSharp {

	/// <summary>
	/// Quick fix that adds static and readonly modifiers to a dependency property field.
	/// </summary>
	[QuickFix]
	public class MakeDpFieldStaticReadOnlyFix : ModifierFixBase {

		protected override void SetModifiers(IModifiersOwnerDeclaration declaration) {
			declaration.SetStatic(true);
			declaration.SetReadonly(true);
		}

		protected override string ModifiersText {
			get {
				var modifiersOwner = (IModifiersOwner) Element;
				if (modifiersOwner.IsStatic && !modifiersOwner.IsReadonly)
					return "readonly";
				if (!modifiersOwner.IsStatic && modifiersOwner.IsReadonly)
					return "static";
				return "static readonly";
			}
		}

		public MakeDpFieldStaticReadOnlyFix(DpFieldMustBeStaticReadOnlyHighlighting highlighting)
			: base(highlighting.FieldDeclaration.DeclaredElement) {
		}
	}

}